public class Test {

    //将两个有序链表合并成一个有序链表
    public static MySingleList.ListNode mergeList(MySingleList.ListNode head1, MySingleList.ListNode head2){
      MySingleList.ListNode newHead=new MySingleList.ListNode(-1);
        MySingleList.ListNode tmp=newHead;
while (head1!=null&&head2!=null){
    if (head1.val<head2.val){
        tmp.next=head1;
        head1=head1.next;
    }else {
        tmp.next=head2;
        head2=head2.next;
    }
    tmp=tmp.next;
}
if (head1!=null){
    tmp.next=head1;
}
if (head2!=null){
    tmp.next=head2;
}
return newHead.next;
    }

    //求两个链表相交节点
    public MySingleList.ListNode getIntersectionNode(MySingleList.ListNode headA, MySingleList.ListNode headB) {
//1先求两个链表长度
int len1=0;
int len2=0;
        MySingleList.ListNode pl=headA;
        MySingleList.ListNode ps=headB;
        while (pl!=null){
            len1++;
            pl=pl.next;
        }
        while (ps!=null){
            len2++;
            ps=ps.next;
        }
        pl=headA;
        ps=headB;
        int len=len1-len2;
       if (len<0){
           pl=headB;
           ps=headA;
           len=len2-len1;
       }
        for (int i = 0; i < len; i++) {//走差值步
            pl=pl.next;
        }
        while (pl!=ps){
            pl=pl.next;
            ps=ps.next;
        }
        return pl;
    }

    public static void main(String[] args) {
        MySingleList mySingleList=new MySingleList();
        MySingleList mySingleList2=new MySingleList();
        mySingleList.addLast(12);
        mySingleList.addLast(23);
        mySingleList.addLast(34);
        mySingleList.addLast(45);
        mySingleList.addLast(56);
        mySingleList2.addLast(8);
        mySingleList2.addLast(15);
        mySingleList2.addLast(30);


        System.out.println();
        //mySingleList.addFirst(78);
        //mySingleList.addLast(94);
        //mySingleList.addIndex(3,112);
       // mySingleList.remove(23);
        //  System.out.println(mySingleList.findKtoTail(5).val);
      //  System.out.println(mySingleList.midNode().val);
        mySingleList.dispaly();
        System.out.println();
        mySingleList2.dispaly();
        //System.out.println(mySingleList.size());
        System.out.println();
        //MySingleList.ListNode nh=mergeList(mySingleList.head,mySingleList2.head);
       // mySingleList.dispaly(nh);
        System.out.println();
       // System.out.println(mySingleList.contains(56));
    }
}
